package com.example.imitation_webchat_demo.model;

import java.util.Comparator;

import com.example.imitation_webchat_demo.entity.T_userInfo;
import com.example.imitation_webchat_demo.util.PinyinUtil;

// 以PhoneInfo中的sortKey字段排序的比较类
public class MyComparator implements Comparator<T_userInfo> {
	@Override
	public int compare(T_userInfo lhs, T_userInfo rhs) {
		char leftChar = PinyinUtil.getPinYin(lhs.getNickname()).charAt(0);
		char rightChar = PinyinUtil.getPinYin(rhs.getNickname()).charAt(0);

		if ((leftChar != '#' && (leftChar > 'Z' || leftChar < 'A'))
				&& rightChar == '#') {
			return -1;
		} else {
			return String
					.valueOf(PinyinUtil.getPinYin(lhs.getNickname()))
					.compareTo(
							String.valueOf(PinyinUtil.getPinYin(rhs.getNickname())));
		}
	}
}